package com.zhang.zhangapp.view.custom;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zhang.zhangapp.R;
import com.zhang.zhangapp.bean.shop.ShopType;
import com.zhang.zhangapp.view.adapter.ShopTypeAdapter;

import java.util.List;

/**
 * Created by Administrator on 2018/4/15.
 */

public class ShopTypeParentLayout extends LinearLayout{

    private ShopType shopType;
    private Context context;
    private WrapHeightGridView gridView;
    private ShopTypeAdapter shopTypeAdapter;
    private TextView titleText;
    private int backgroundRes = -1;
    public ShopTypeParentLayout(Context context,ShopType shopType) {
        super(context);
        this.shopType =shopType;
        this.context = context;
        initView();
    }

    public ShopTypeParentLayout(Context context,ShopType shopType,int backgroundRes) {
        super(context);
        this.shopType =shopType;
        this.context = context;
        this.backgroundRes = backgroundRes;
        initView();
    }

    private void initView(){
        LayoutInflater.from(context).inflate(R.layout.item_shop_parent_type,this);
        shopTypeAdapter = new ShopTypeAdapter(shopType.getChild(),context,backgroundRes);
        gridView = (WrapHeightGridView)this.findViewById(R.id.wrap_grid_view);
        titleText = (TextView)this.findViewById(R.id.item_shop_type_name);
        titleText.setText(shopType.getName());
        gridView.setAdapter(shopTypeAdapter);
    }

    public void setOnClickListener(AdapterView.OnItemClickListener listener){
        gridView.setOnItemClickListener(listener);
    }
}
